home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performSubdToNurbs.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  8.5 KB  |  358 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  18 January, 2001
  22. //
  23. //
  24. //  Description:
  25. //        Option box for subdivision surfaces extract
  26. //
  27.  
  28. //
  29. //  Procedure Name:
  30. //      setOptionVars
  31. //
  32. //  Description:
  33. //        Initialize the option values.
  34. //
  35. //  Input Arguments:
  36. //        Whether to set the options to default values.
  37. //
  38. //  Return Value:
  39. //      None.
  40. //
  41. //  Note:
  42. //     Commented out Type option for this rev
  43. //
  44. proc setOptionVars(int $forceFactorySettings)
  45. {
  46.  
  47.     //  Original Object
  48.     //    
  49.     if ($forceFactorySettings ||
  50.         !`optionVar -exists subdToNurbsOrigObject`) {
  51.         optionVar -intValue subdToNurbsOrigObject 1;
  52.     }
  53.  
  54.     if ($forceFactorySettings ||
  55.         !`optionVar -exists subdToNurbsOutputType`) {
  56.         optionVar -intValue subdToNurbsOutputType 0;
  57.     }
  58. }
  59.  
  60.  
  61. //
  62. //  Procedure Name:
  63. //      subdToNurbsSetup
  64. //
  65. //  Description:
  66. //        Update the state of the option box UI to reflect the option values.
  67. //
  68. //  Input Arguments:
  69. //      parent               - Top level parent layout of the option box UI.
  70. //                             Required so that UI object names can be 
  71. //                             successfully resolved.
  72. //
  73. //    forceFactorySettings - Whether the option values should be set to
  74. //                             default values.
  75. //
  76. //  Return Value:
  77. //      None.
  78. //
  79. global proc subdToNurbsSetup(string $parent, int $forceFactorySettings)
  80. {
  81.     int $method;
  82.  
  83.     //    Retrieve the option settings
  84.     //
  85.     setOptionVars($forceFactorySettings);
  86.  
  87.     setParent $parent;
  88.  
  89.     //    Query the optionVar's and set the values into the controls.
  90.     int $outputType = `optionVar -query subdToNurbsOutputType`+1;
  91.     radioButtonGrp -edit -select $outputType subdToNurbsOutputTypeRadioButtonGrp;
  92.  
  93.     //  Original Object
  94.     int $origObject = `optionVar -query subdToNurbsOrigObject`;
  95.     radioButtonGrp -edit -select $origObject subdToNurbsOrigObjectWidget;
  96. }
  97.  
  98. //
  99. //  Procedure Name:
  100. //      subdToNurbsCallback
  101. //
  102. //  Description:
  103. //        Update the option values with the current state of the option box UI.
  104. //
  105. //  Input Arguments:
  106. //      parent - Top level parent layout of the option box UI.  Required so
  107. //               that UI object names can be successfully resolved.
  108. //
  109. //    doIt   - Whether the command should execute.
  110. //
  111. //  Return Value:
  112. //      None.
  113. //
  114. global proc subdToNurbsCallback(string $parent, int $doIt)
  115. {
  116.     setParent $parent;
  117.  
  118.     //    Set the optionVar's from the control values, and then
  119.     //    perform the command.
  120.  
  121.     optionVar -intValue subdToNurbsOrigObject
  122.         `radioButtonGrp -q -select subdToNurbsOrigObjectWidget`;
  123.  
  124.     int $outputType = `radioButtonGrp -q -select subdToNurbsOutputTypeRadioButtonGrp` -1;
  125.     optionVar -intValue subdToNurbsOutputType $outputType;
  126.  
  127.     if ($doIt) {
  128.         performSubdToNurbs 0; 
  129.         addToRecentCommandQueue "performSubdToNurbs 0" "Convert";
  130.     }
  131. }
  132.  
  133. //
  134. //  Procedure Name:
  135. //      subdToNurbsOptions
  136. //
  137. //  Description:
  138. //        Construct the option box UI.  Involves accessing the standard option
  139. //        box and customizing the UI accordingly.
  140. //
  141. //  Input Arguments:
  142. //      None.
  143. //
  144. //  Return Value:
  145. //      None.
  146. //
  147. proc subdToNurbsOptions()
  148. {
  149.     //    Name of the command for this option box.
  150.     //
  151.     string $commandName = "subdToNurbs";
  152.  
  153.     //    Build the option box actions.
  154.     //
  155.     string $callback = ($commandName + "Callback");
  156.     string $setup = ($commandName + "Setup");
  157.  
  158.     //    STEP 1:  Get the option box.
  159.     //    ============================
  160.     //
  161.     string $layout = getOptionBox();
  162.     setParent $layout;
  163.     
  164.     //    STEP 2:  Pass the command name to the option box.
  165.     //    =================================================
  166.     //
  167.     setOptionBoxCommandName($commandName);
  168.     
  169.     //    STEP 3:  Activate the default UI template.
  170.     //    ==========================================
  171.     //
  172.     setUITemplate -pushTemplate DefaultTemplate;
  173.  
  174.     //    STEP 4: Create option box contents.
  175.     //    ===================================
  176.     //    
  177.     
  178.     //    Turn on the wait cursor.
  179.     //
  180.     waitCursor -state 1;
  181.  
  182.     tabLayout -tabsVisible 0 -scrollable 1;
  183.     
  184.     string $parent = `columnLayout -adjustableColumn 1`;
  185.     
  186.     //    Original object
  187.     //    
  188.     radioButtonGrp 
  189.         -numberOfRadioButtons 3
  190.         -label "Original Object"
  191.         -l1 "Replace"
  192.         -l2 "Hide"
  193.         -l3 "Show"
  194.         subdToNurbsOrigObjectWidget;
  195.  
  196.    radioButtonGrp -nrb 2
  197.        -l "Output Type" 
  198.        -l1 "NURBS" 
  199.        -l2 "Beziers" 
  200.        subdToNurbsOutputTypeRadioButtonGrp;
  201.  
  202.     //    Turn off the wait cursor.
  203.     //
  204.     waitCursor -state 0;
  205.     
  206.     //    Step 5: Deactivate the default UI template.
  207.     //    ===========================================
  208.     //
  209.     setUITemplate -popTemplate;
  210.  
  211.     //    Step 6: Customize the buttons.  
  212.     //    ==============================
  213.     //
  214.  
  215.     //    'Apply' button.
  216.     //
  217.     string $applyBtn = getOptionBoxApplyBtn();
  218.     button -edit -l "Convert"
  219.         -command ($callback + " " + $parent + " " + 1)
  220.         $applyBtn;
  221.  
  222.     //    'Save' button.
  223.     //
  224.     string $saveBtn = getOptionBoxSaveBtn();
  225.     button -edit 
  226.         -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox")
  227.         $saveBtn;
  228.  
  229.     //    'Reset' button.
  230.     //
  231.     string $resetBtn = getOptionBoxResetBtn();
  232.     button -edit 
  233.         -command ($setup + " " + $parent + " " + 1)
  234.         $resetBtn;
  235.  
  236.     //    Step 7: Set the option box title.
  237.     //    =================================
  238.     //
  239.     setOptionBoxTitle("Convert Subdiv to NURBS Options");
  240.  
  241.     //    Step 8: Customize the 'Help' menu item text.
  242.     //    ============================================
  243.     //
  244.     setOptionBoxHelpTag( "SubdivtoNURBS" );
  245.  
  246.     //    Step 9: Set the current values of the option box.
  247.     //    =================================================
  248.     //
  249.     eval (($setup + " " + $parent + " " + 0));    
  250.     
  251.     //    Step 10: Show the option box.
  252.     //    =============================
  253.     //
  254.     showOptionBox();
  255. }
  256.  
  257. //
  258. //  Procedure Name:
  259. //      subdToNurbsHelp
  260. //
  261. //  Description:
  262. //        Return a short description about this command.
  263. //
  264. //  Input Arguments:
  265. //      None.
  266. //
  267. //  Return Value:
  268. //      string.
  269. //
  270. proc string subdToNurbsHelp()
  271. {
  272.     return 
  273.     "  Command: subdivToPoly - convert subdivision surfaces into multiple NURBS.\n" +
  274.     "Selection: Subdivision surfaces.";
  275. }
  276.  
  277. //
  278. //  Procedure Name:
  279. //      assembleCmd
  280. //
  281. //  Description:
  282. //        Construct the command that will apply the option box values.
  283. //
  284. //  Input Arguments:
  285. //      None.
  286. //
  287. proc string assembleCmd()
  288. {
  289.     setOptionVars(false);
  290.     
  291.     int $origObject = `optionVar -q subdToNurbsOrigObject`;
  292.     int $doHistory = `constructionHistory -q -tgl`;
  293.  
  294.     int $outputType = `optionVar -query subdToNurbsOutputType`;
  295.     
  296.     string $cmd = "doSubdivToNurbs";
  297.     $cmd = $cmd + "( {\"";
  298.     $cmd = $cmd + $doHistory;
  299.     $cmd = $cmd + "\",\"";
  300.     $cmd = $cmd + $origObject;
  301.     $cmd = $cmd + "\",\"";
  302.     $cmd = $cmd + $outputType;
  303.     $cmd = $cmd + "\"} )";
  304.  
  305.     return $cmd;
  306. }
  307.  
  308. //
  309. //  Procedure Name:
  310. //      performSubdToNurbs
  311. //
  312. //  Description:
  313. //        Perform the performSubdToNurbs command using the corresponding 
  314. //        option values.  This procedure will also show the option box
  315. //        window if necessary as well as construct the command string
  316. //        that will invoke the performSubdToNurbs command with the current
  317. //        option box values.
  318. //
  319. //  Input Arguments:
  320. //      0 - Execute the command.
  321. //      1 - Show the option box dialog.
  322. //      2 - Return the command.
  323. //
  324. global proc string performSubdToNurbs(int $action)
  325. {
  326.     string $cmd = "";
  327.     switch ($action) {
  328.  
  329.         //    Execute the command.
  330.         //
  331.         case 0:
  332.             //    Get the command.
  333.             //
  334.             $cmd = `assembleCmd`;
  335.  
  336.             //    Execute the command with the option settings.
  337.             //
  338.             eval($cmd);
  339.  
  340.             break;
  341.  
  342.         //    Show the option box.
  343.         //
  344.         case 1:
  345.             subdToNurbsOptions;
  346.             break;
  347.  
  348.         //    Return the command string.
  349.         //
  350.         case 2:
  351.             //    Get the command.
  352.             //
  353.             $cmd = `assembleCmd`;
  354.             break;
  355.     }
  356.     return $cmd;
  357. }
  358.